Package aspect.example

Source Code of aspect.example.Planet

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aspect.example;

import aspect.entity.Entity;
import aspect.physics.RigidBody;
import aspect.render.Material;
import aspect.render.ViewModel;
import static aspect.resources.Resources.*;
import aspect.util.Trig;
import aspect.util.Vector3;
import aspect.world.World;
import java.io.File;

/**
*
* @author MillerV
*/
public class Planet extends SpaceObject {

    public final float radius;

    public Planet(Material mat, float radius, float density) {
        super(sphere(radius, 50, mat), (4.0f / 3.0f) * Trig.PI * radius * radius * radius * density);

        this.radius = radius;
    }

    @Override
    public void update() {
        super.update();
        for (Entity entity : World.main) {
            if (entity != this && entity instanceof Planet) {
                Planet planet = (Planet) entity;
                if (Vector3.distance(transform.position, planet.transform.position) < radius + planet.radius) {
                    RigidBody rb1 = rigidBody();
                    RigidBody rb2 = planet.rigidBody();
                   
                    Vector3 momentum = rb1.velocity.times(rb1.mass).plus(rb2.velocity.times(rb2.mass));
                   
                    float mass = rb1.mass + rb2.mass;
                   
                    float vol1 = (4.0f / 3.0f) * Trig.PI * radius * radius * radius;
                    float vol2 = (4.0f / 3.0f) * Trig.PI * planet.radius * planet.radius * planet.radius;
                   
                    float newradius = (float)Math.pow((vol1 + vol2) / ((4.0f / 3.0f) * Trig.PI), 1.0f / 3.0f);
                   
                    Planet result = new Planet(loadMaterial(new File("materials/planet_crashed.amp")), newradius, mass / (vol1 + vol2));
                    result.transform.position = transform.position.times(rb1.mass).plus(planet.transform.position.times(rb2.mass)).times(1.0f / mass);
                   
                    System.out.println(result.transform.position);
                    result.rigidBody().velocity = Vector3.divide(momentum, mass);
                   
                    destroy();
                    planet.destroy();
                    World.main.add(result);
                    break;
                   
                }
            }
        }
    }
}
TOP

Related Classes of aspect.example.Planet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.